﻿using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

public class LibraryModel {
	// === Public =====================================================================================================
	public ExtensionTypeGroup LibType { get; set; }
	public string LibName {
		get { return _libName; }
		set {
			_libName = value;
			RefreshLibPath();
		}
	}
	[XmlIgnore]
	public string LibRootPath {
		get { return _libRootPath; }
		set {
			_libRootPath = value;
			RefreshLibPath();
		}
	}
	[XmlIgnore]
	public string LibPath { get; set; }
	[XmlArray("Assets")]
	[XmlArrayItem(typeof(Asset))]
	public List<Asset> Assets { get; set; }

	public LibraryModel() {
		LibName = string.Empty;
		LibRootPath = string.Empty;
		LibPath = string.Empty;
		Assets = new List<Asset>();
	}

	public void Init() {
		LibRootPath = Directory.GetCurrentDirectory();
		foreach(var asset in Assets) {
			asset.RefreshAsset(LibPath);
		}
	}

	// === Private ====================================================================================================
	private string _libName = "";
	private string _libRootPath = "";

	private void RefreshLibPath() {
		LibPath = Path.Combine(LibRootPath, LibName);
	}
}